package xyz.scootaloo.oj.iq

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester

/**
 * @author flutterdash@qq.com
 * @since 2021/4/15 9:15
 */
class M0104 {

    fun canPermutePalindrome(s: String): Boolean {
        val cache = IntArray(128)
        for (c in s) {
            cache[c.toInt()]++
        }

        var odd = 0  // 单数
        for (num in cache) {
            if (num == 0)
                continue
            if (num % 2 == 1) {
                if (odd == 1)
                    return false
                odd++
            }
        }

        return true
    }

    @Test
    fun test0() {
        Tester.createTest(this::canPermutePalindrome)
            .addCase("tactcoa", true)
            .addCase("tactcoab", false)
            .addCase("t", true)
            .addCase("AaBb//a", false)
            .testAndShow()
    }

}
